<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>model1</title>
</head>
<script src="./config.js"></script>
<script src="./3dEngine/js/3dEngine.demo.js"></script>
<style>
  * {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
  }
  html,body {
    height: 100%;
    width: 100%;
  }
  #viewer1 {
    width: 100%;
    height: 100%;
  }

  .tips_show {
    padding: 10px;
    background: url('./img/meter_bg.png') no-repeat center;
    background-size: contain;
    border-radius: 4px;
    position: absolute;
    top: -120px;
    right: 40px;
    filter: drop-shadow(1px 1px 7px #333);
    bottom: 0px;
    box-sizing: border-box;
    pointer-events: initial;
    font-size: 12px;
    color: #fff;
    text-align: left;
    width: 120px;
    height: 76px;
    font-family: Microsoft YaHei Regular;
    cursor: pointer;
  }

  .line {
    position: absolute;
    background: url('./img/meter_line.jpg') no-repeat center;
    background-size: contain;
    width: 73px;
    height: 54px;
    left: 75%;
    top: 90%;
  }
  .tips_show p {
    margin: 0;
    font-size: 12px;
    color: #FFFFFFD9;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .tips_show p:first-child {
    color: #84FEFF;
    font-size: 14px;
  }
  #percent {
    font-size: 35px;
    color: #0078D7;
    line-height: 100px;
    text-align: center;
    width: 100px;
    height: 100px;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    border: 5px solid #0078D7;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    display: none;
  }
</style>
<body>
  <div id="viewer1"></div>
  <div id="percent"></div>
</body>
<script>
  var ws = new WebSocket(`${window.R_config.commonSocket}:8020`)
  ws.onopen = function() {
    console.log('工艺区2 已连接')
  }
  var meters = [
    {
      bit: 'TE-1263D',
      pos: '-18206.052346943405,-272.40163281921787,3163.825666458786'
    },
    {
      bit: 'TE-1266',
      pos: '-25976.123839748507,-4271.4361391746315,7219.532084721483'
    },
    {
      bit: 'TE-1260B',
      pos: '-13716.756024709073,3543.622463465765,7229.797888429726'
    },
    {
      bit: 'TE-1261',
      pos: '-11946.654647573372,11551.177538484153,7625.42883723337'
    },
    {
      bit: 'PT-1268',
      pos: '-17155.337936403164,-2420.223359928223,13459.345536009216'
    }
  ]
  EngineConfig("viewer1", false);
  SetYup(true);
  SetLightMode(1);
  SetBackImg('./img/back.png');
  
  var offSetX = -11000;
  var offSetY = -9400;
  var offSetZ = -6700;
  
  AddEnvModel('https://model.richtechcn.com/spc2/spctest9.zb',offSetX,offSetY,offSetZ,true);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest2.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest3.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest4.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest5.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest6.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest7.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest8.zb',offSetX,offSetY,offSetZ,false);
  AddEnvModel('https://model.richtechcn.com/spc2/spctest1.zb',offSetX,offSetY,offSetZ,false);
  // AddEnvModel('https://model.richtechcn.com/ttest/spc2.zb',0,0,0,"-3013.3956040940247,14587.705699408427,17203.57025622736,-4232.998352423625,-119353.37319155432,34.147052132802216,-0.558590718433456,2.476058992239111", false, true);
  
  AddModel('http://model.richtechcn.com/bottle0/bottle0.json', '66');
  SetAutoRotate(true);
  function addLabel() {
    meters.forEach((n, index) => {
      var htmlStr = `<div id="tips_show" class='tips_show'>
        <p>${n.bit}</p>
        <p id="tag_${n.bit}"></p>
        <p class="p-value" id='QValue_${n.bit}'></p>
        <span class="line"></span>
        </div>`
        AddHtmlMarker(n.pos, htmlStr, 'marker' + index)
    })
  }
  function OnModelLoaded() {
    SetView("-14495.202194330639,-2610.8500873531057,6294.813620592282,-248.2384447506939,-97686.00106345245,6454.199563538581,-0.7853981633974483,-0.09939816339744767");
      var posArray = [];

      posArray.push('-9535.546525008187,11242.110661872674,12378.433642019705');
      posArray.push('-9709.567413871679,11353.105862041877,14686.772894154485');
      posArray.push('-10766.585427987095,12172.780969225318,14899.402390617492');
      posArray.push('-28650.04343952505,12152.638272585573,14700.21914973687');
      posArray.push('-29145.026631434583,11480.275621020117,14706.049208934071');
      posArray.push('-28731.9342203187,10078.33360706844,14612.694076569092');

      posArray.push('-13453.056201268133,10144.888695077043,14631.916783615792');
      posArray.push('-12496.929899091065,8894.74264838946,14715.188090718859');
      posArray.push('-7702.231876336658,9225.149835337948,14533.005052641833');
      posArray.push('-7660.838731043505,9100.686370481304,2408.9810751953346');
      posArray.push('-7639.798179830763,4762.502163453766,2448.697576804263');
      posArray.push('-7513.021964645988,4492.760494127579,12504.952023136346');
      posArray.push('-7535.86378696893,-8578.61315063695,12540.614510034817');
      posArray.push('-8876.567166846888,-9691.52464923414,12135.585532390893');
      posArray.push('-8743.368500104301,-9520.582922570597,6530.718569660937');
      posArray.push('-8573.173965423659,-7834.996631729173,6464.7116066135095');
      posArray.push('-6406.642642920238,-7871.148920536596,6523.746366506087');
      posArray.push('-6190.541999714271,-7809.28482896141,5845.327689360615');
        setTimeout(function () {
        AddFlow('flow0','./img/flow2.png',posArray,80);
      }, 1000);

      AddLiquidNode('tag0_1#tag0_2#tag0_3','liquid0',0,0,255,0.35);
        
      UpdateLiquidValue('liquid0',0.2,1.0, 100000,0,true);

  }
  function OnLoadModelProcess(value) {
    console.log(value)
    var a = document.getElementById('percent')
    a.innerText = Math.floor(value*100) + '%'
    if (value === 1) {
      a.style.display = 'none'
    } else {
      a.style.display = 'block'
    }
  }
  
  function OnClickPosition(position) {
    console.log('点击位置' + position)
  }
  ws.onmessage = function(evt) { 
    if (evt.data.includes('Echo')) return
    var dat = JSON.parse(evt.data)
    // console.log(dat)
    if (dat.Key === 'GetDeviceListData') {
      let dd = JSON.parse(dat.Data)
      // console.log(dd)
      dd.forEach(n => {
        if (document.getElementById(`tag_${n.DeviceName}`)) {
          document.getElementById(`tag_${n.DeviceName}`).innerText = n.TagDes
          document.getElementById(`QValue_${n.DeviceName}`).innerText = n.Qvalue + n.Unit || ''
        }
      })
    }
  }
      setTimeout(() => {
        addLabel()
      }, 5000)
  setInterval(function(){
    var ping = {"type":"ping"}
    ws.send(JSON.stringify(ping))
  }, 50000)
</script>
</html>